import requests
class ProxyHelper(object):
    def __init__(self):
        self.proxy = self._get_proxy_from_mogu()

    def get_proxy(self):
        return self.proxy

    def update_proxy(self, proxy):
        if proxy == self.proxy:
            print('更新了一个proxy', self.proxy)
            self.proxy = self._get_proxy_from_mogu()

    def _get_proxy_from_mogu(self):
        url = 'http://piping.mogumiao.com/proxy/api/get_ip_al?appKey=4015b4545c6545d5b21a3b49fec0671c&count=1&expiryDate=0&format=2&newLine=2'
        print('我，获取了一个代理')
        response = requests.get(url)
        return 'http://' + response.text.strip()

if __name__ == '__main__':
    helper = ProxyHelper()
    print(helper.get_proxy())
    helper.update_proxy()
    import time

    time.sleep(5)
    print(helper.get_proxy())